//
//  HWGameLiveChatBottomView.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/10/26.
//

import UIKit

class HWGameLiveChatBottomView: UIView {
    var chatButtonBgView:UIView!
    var chatButtonTitle:UILabel!
    // 聊一聊
    var chatButton:UIButton!
    /// 管理
    var managerButton:UIButton!
    /// 礼物
    var giftButton:UIButton!
    
    var chatButtonClick:(()->())?
    var giftButtonClick:(()->())?
    var managerButtonClick:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
        
        initFrame()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    
}
extension HWGameLiveChatBottomView{
    private func initUI() -> Void {
        backgroundColor = UIColor.colorWithAlphaHexString(hexString: "#FFFFFF", alpha: 1)
        
        chatButtonBgView = UIView()
        chatButtonBgView.backgroundColor = .colorWithHexString(hexString: "#F6F6F6")
        chatButtonBgView.layer.cornerRadius = 32*widthScale/2
        addSubview(chatButtonBgView)
        
        chatButtonTitle = HWLabel.createLabel(title: "说点什么...", color: "#999999", font: 14*widthScale)
        chatButtonBgView.addSubview(chatButtonTitle)
        
        
        chatButton = UIButton.init(type: UIButton.ButtonType.custom)
        chatButton.addTarget(self, action: #selector(chatButtonClick(_:)), for: UIControl.Event.touchUpInside)
        chatButtonBgView.addSubview(chatButton)
        
        
        managerButton = UIButton.init(type: UIButton.ButtonType.custom)
        managerButton.backgroundColor = .clear
        managerButton.setImage(UIImage(named: "gameLiveMore"), for: UIControl.State.normal)
        managerButton.layer.borderColor = UIColor.white.cgColor
        managerButton.addTarget(self, action: #selector(managerButtonClick(_:)), for: UIControl.Event.touchUpInside)
        managerButton.isHidden = true
        addSubview(managerButton)
        
        giftButton = UIButton.init(type: UIButton.ButtonType.custom)
        giftButton.backgroundColor = .clear
        giftButton.setImage(UIImage(named: "gameLiveGift"), for: UIControl.State.normal)
        giftButton.layer.borderColor = UIColor.white.cgColor
        giftButton.addTarget(self, action: #selector(giftButtonClick(_:)), for: UIControl.Event.touchUpInside)
        addSubview(giftButton)
        
        
    }
    
    private func initFrame() -> Void {
        
        chatButtonBgView.snp.makeConstraints { make in
            make.left.equalTo(16*widthScale)
            make.top.equalTo(11*widthScale)
//            make.width.equalTo(190*widthScale)
            make.width.equalTo(290*widthScale)
            make.height.equalTo(32*widthScale)
        }
        
        
        chatButtonTitle.snp.makeConstraints { make in
            make.left.equalTo(15*widthScale)
            make.centerY.equalToSuperview()
        }
        
        chatButton.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        giftButton.snp.makeConstraints { make in
            make.right.equalTo(-15*widthScale)
            make.centerY.equalTo(chatButtonBgView)
            make.width.height.equalTo(36*widthScale)
        }
        
        managerButton.snp.makeConstraints { make in
            make.right.equalTo(giftButton.snp.left).offset(-20*widthScale)
            make.centerY.equalTo(chatButtonBgView)
            make.width.height.equalTo(36*widthScale)
        }
        
    }
}

extension HWGameLiveChatBottomView{
    @objc func chatButtonClick(_ button:UIButton) -> Void {
        self.chatButtonClick?()
    }
    
    @objc func managerButtonClick(_ button:UIButton) -> Void {
        self.managerButtonClick?()
        
    }
    
    @objc func giftButtonClick(_ button:UIButton) -> Void {
        self.giftButtonClick?()
    }
}
